//
//  MainViewController.swift
//  SinaWeiBo
//
//  Created by 有风 on 16/1/30.
//  Copyright © 2016年 YouFeng. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainBar = MainTabBar()
        setValue(mainBar, forKey: "tabBar")
        addChildViewControllers()
        
        //添加plus点击事件
        mainBar.plusBtn.addTarget(self, action: "plusBtnClick", forControlEvents: .TouchUpInside)
    }

    @objc private func plusBtnClick() {
        print(__FUNCTION__)
        let plusVC = ComposeViewController()
        let plusNavi = UINavigationController(rootViewController: plusVC)
        self.presentViewController(plusNavi, animated: true) { () -> Void in
        }
    }
    
    private func addChildViewControllers() {
        tabBar.tintColor = UIColor.orangeColor()
        addChildViewController("首页", VC: HomeTableViewController(), itemImageString: "tabbar_home")
        addChildViewController("信息", VC: MessageTableViewController(), itemImageString: "tabbar_message_center")
        addChildViewController("发现", VC: DiscoverTableViewController(), itemImageString: "tabbar_discover")
        addChildViewController("我", VC: ProfileTableViewController(), itemImageString: "tabbar_profile")
    }
    
    private func addChildViewController(titleString : String,VC : UIViewController,itemImageString : String) {
        
        VC.title = titleString
        VC.tabBarItem.image = UIImage(named: itemImageString)
        let navi = BaseNavigationController(rootViewController: VC)
        addChildViewController(navi)
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
